home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
M
/
MacBinary C Source.cpt
/
MacBinary C Source
Wrap
Text File
|
1991-12-05
|
7KB
|
279 lines
/* DON'T IGNORE THESE COMMENTS!
The compiled version of this file can be used to convert a
MacBinary file to the forked format used by the Macintosh.
This is useful if you have a modem on the PC, but no way
to conveniently get MacUsable copies of UnStuffIt and MB2MAC
onto the Mac. To gain MacBinary capability, compile this and
use it on both MB2MAC.SIT and UNSTUFF.SEA. The Mac format
UNSTUFF can then be used to unpack MB2MAC.SIT, which goes into
the Apple File Exchange folder. At that point, you can eliminate
the extra step of using this program to convert everything. I would
recoment using MB2MAC anyway, because this program is not what
I would call "Industrial Strength".
I originally wrote this program using a resource file, hence
the _SOURCEONLY_ define found down below. Transfering a resource
file didn't make a whole lot of sense, so the program has been
changed to allow text only uploads and downloads.
This program is hereby placed into the public domain. If you choose
to distribute it (please do!!), please distribute it unchanged. I
wrote it in Think C, but there is no compiler specific stuff except
maybe the <Menus.h> include file.
This program works on my mac, therefore it should work on yours. The
only programs that I've tested it on are MB2MAC.SIT and STUFFIT.SEA.
By the way, this is the first Macintosh program I've ever done. I
haven't included any 'in progress' information, so don't panic
if nothing seems to be happening if you are converting a large file.
This file was originally saved using the DOS style newlines. If you
ran it through Apple File Exchange using the default translation, do
it again, this time using the text translation method.
There are two files on CIS that explain how this program does
what it does. If interested, check out MACBIN.STD and MB2STD.TXT.
I've forgotten which forums they are in.
David Schooley, CIS ID: 72571,2543
November 18, 1991
*/
#include <Menus.h>
#define _SOURCEONLY_
int MacEventCheck(void);
int DoMenu(long startPoint);
void DoTranslate(void);
#define APPLEID 128
#define FILEID 129
#define EDITID 130
#define APPLEM 0
#define FILEM 1
#define EDITM 2
#ifndef _SOURCEONLY_
#define MENUCOUNT 3
#else
#define MENUCOUNT 2
#endif
MenuHandle menuList[MENUCOUNT];
int main()
{
int fileID;
int i;
/* Initialize the Mac */
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
TEInit();
InitDialogs(NULL);
InitCursor();
/* Set up the menu bar */
InitMenus();
#ifndef _SOURCEONLY_
/* This section is only compiled if _SOURCEONLY_ is NOT defined */
GetResource('MENU', fileID);
menuList[APPLEM] = GetMenu(APPLEID);
AddResMenu(menuList[APPLEM], 'DRVR');
menuList[FILEM] = GetMenu(FILEID);
menuList[EDITM] = GetMenu(EDITID);
#else
/* This section is compiled if _SOURCEONLY_ is defined. */
menuList[APPLEM] = NewMenu(APPLEID, "\p\024");
/* I have yet to figure out why the above statement puts up */
/* the Apple, but it works! */
/* Now enable the apple menu list */
AddResMenu(menuList[APPLEM], 'DRVR');
menuList[FILEM] = NewMenu(FILEID, "\pFile");
/* Now add the menu items */
AppendMenu(menuList[FILEM], "\pOpen/O;(-;Quit/Q");
#endif
/* Do the rest all of the time */
for (i = 0; i < MENUCOUNT; i++)
InsertMenu(menuList[i], 0);
DrawMenuBar();
/* Do the event loop */
while(MacEventCheck());
}
int MacEventCheck(void)
{
EventRecord currentEvent;
Point mouseLoc;
WindowPtr hotWindow;
int result;
SystemTask(); /* Be nice to the rest of the system */
if(!GetNextEvent(everyEvent, ¤tEvent))
return(-1);
/* If we are this far, that means something happened */
switch (currentEvent.what) {
case mouseDown: GetMouse(&mouseLoc);
switch(FindWindow(mouseLoc, &hotWindow)) {
case inSysWindow: SystemClick(¤tEvent, hotWindow);
break;
case inMenuBar: result = DoMenu(MenuSelect(mouseLoc));
break;
case inDrag: /* DragWindow(hotWindow, mouseLoc, DragRect);*/
break;
} /* End of 'FindWindow' switch */
} /* End the switch here for now */
return(result);
}
int DoMenu(long start)
{
int theItem;
int result;
Str255 name;
theItem = LoWord(start);
switch (HiWord(start)) {
case APPLEID:
GetItem(menuList[APPLEM], theItem, &name);
OpenDeskAcc(name);
result = -1;
break;
case FILEID:
switch (theItem) {
case 1: DoTranslate();
result = 0;
break;
case 3: result = 0;
break;
}
break;
}
}
void DoTranslate(void)
{
/* Data for the input file */
SFReply fileStruct;
Str255 inputPrompt = "Input File";
SFTypeList typeList;
Point diaStart = {30,30};
int inputReferenceNum;
char header[128];
long inputCount = 128;
/* Pointers to header information */
long *fileType;
long *fileCreator;
char *finderFlags;
long *dataForkLength;
long *resForkLength;
int *getInfoLength;
/* Other variables
long resourceLength, dataLength;
/* Data for the output file */
SFReply outputFileStruct;
Str255 outputPrompt = "\0xCOutput File";
Str255 initialOut = "";
Point diaStartOut = {30, 30};
int outputReferenceNum;
int outputResRefNum;
long dataLength, resourceLength;
outputFileStruct.good = 0;
SFGetFile(diaStart, inputPrompt, NULL, -1, typeList, NULL, &fileStruct);
if (fileStruct.good)
SFPutFile(diaStartOut, outputPrompt, initialOut, NULL, &outputFileStruct);
if (outputFileStruct.good) {
/* If we are here, then we got valid entries for both dialogs */
/* Open up the input file using the data we got from the dialog*/
if (FSOpen(fileStruct.fName, fileStruct.vRefNum, &inputReferenceNum) != noErr)
return;
/* Read in the header information */
SetFPos(inputReferenceNum, fsFromStart, 0);
FSRead(inputReferenceNum, &inputCount, header);
fileType = (long*) &header[65];
fileCreator = (long*) &header[69];
finderFlags = &header[73];
dataForkLength = (long*) &header[83];
resForkLength = (long*) &header[87];
getInfoLength = (int*) &header[99];
dataLength = *dataForkLength;
resourceLength = *resForkLength;
/* Create the output file */
if (Create(outputFileStruct.fName, outputFileStruct.vRefNum, *fileCreator, *fileType) != noErr)
return;
FSOpen(outputFileStruct.fName, outputFileStruct.vRefNum, &outputReferenceNum);
/* Transfer the data fork first */
inputCount = 128;
SetFPos(inputReferenceNum, fsFromStart, 128);
for(; dataLength > 0; dataLength -= 128) {
FSRead(inputReferenceNum, &inputCount, header);
if (dataLength >= 128)
FSWrite(outputReferenceNum, &inputCount, header);
else
FSWrite(outputReferenceNum, &dataLength, header);
}
/* Now transfer the resource fork */
OpenRF(outputFileStruct.fName, outputFileStruct.vRefNum, &outputResRefNum);
for (; resourceLength > 0; resourceLength -= 128) {
FSRead(inputReferenceNum, &inputCount, header);
if (resourceLength >= 128)
FSWrite(outputResRefNum, &inputCount, header);
else
FSWrite(outputResRefNum, &resourceLength, header);
}
/* All done, now close the file */
FSClose(outputReferenceNum);
FSClose(outputResRefNum);
FSClose(inputReferenceNum);
FlushVol(outputFileStruct.fName, outputReferenceNum);
FlushVol(outputFileStruct.fName, outputResRefNum);
}
}